<template>
  <div>
    <div>
      <el-form inline label-width="100px" label-position="left">
        <el-row>
          <el-form-item label="申请编号：">
            <el-input v-model="sqbh" placeholder="请输入申请编号"></el-input>
          </el-form-item>
          <el-form-item label="客户名称：">
            <el-input
              v-model="customerName"
              placeholder="请输入客户名称"
            ></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item
            label="证件号码："
            label-position="left"
            style="padding-top: 10px"
          >
            <el-input v-model="idNo" placeholder="请输入证件号码"></el-input>
          </el-form-item>
          <el-form-item style="padding-top: 50px">
            <el-button type="primary" @click="queryInfo" size="medium"
              >查询</el-button
            >
          </el-form-item>
          <el-form-item style="padding-top: 50px">
            <el-button type="primary" @click="restAll" size="medium"
              >重置</el-button
            >
          </el-form-item>
        </el-row>
      </el-form>
    </div>

    <div style="padding-top: 20px">
      <el-table
        :data="custInfo"
        title="客户资料查询"
        border
        height="300"
        stripe="true"
        style="width: 100%"
        @cell-click="showRepayDialog"
      >
        <!-- <el-table-column type="selection" :selectable="selectable" /> -->
        <el-table-column
          prop="applSeq"
          label="申请编号"
          width="120"
          align="center"
        />
        <el-table-column
          prop="custName"
          label="客户名称"
          width="120"
          align="center"
        />
        <el-table-column
          prop="idNo"
          label="证件号码"
          width="120"
          align="center"
        />
        <el-table-column
          prop="cooprName"
          label="门店"
          width="120"
          align="center"
        />
        <el-table-column
          prop="appOrigin"
          label="业务端来源"
          width="120"
          align="center"
        />
        <el-table-column
          prop="bchCde"
          label="所属机构"
          width="120"
          align="center"
        />
        <el-table-column
          prop="loanTyp"
          label="业务品种"
          width="80"
          align="center"
        />
        <el-table-column
          prop="docChannel"
          label="进件通路"
          width="120"
          align="center"
        />
        <el-table-column
          prop="applyAmt"
          label="申请金额"
          width="120"
          align="center"
        />
        <el-table-column
          prop="apprvAmt"
          label="审批金额"
          width="120"
          align="center"
        />
        <el-table-column
          prop="applyTnr"
          label="申请期限"
          width="120"
          align="center"
        />
        <el-table-column
          prop="wfiIntoPiecesMarked"
          label="申请件类型"
          width="120"
          align="center"
        />
        <el-table-column
          prop="applyDt"
          label="申请日期"
          width="120"
          align="center"
        />
        <el-table-column
          prop="inStsDesc"
          label="申请状态"
          width="120"
          align="center"
        />
        <el-table-column
          prop="nodeOverTime"
          label="进件时长"
          width="120"
          align="center"
        />
        <el-table-column
          prop="nodeOnTime"
          label="持续时长"
          width="120"
          align="center"
        />
        <el-table-column
          prop="custGrade"
          label="客户评级"
          width="120"
          align="center"
        />
        <el-table-column
          prop="complaintRank"
          label="客户投诉等级"
          width="120"
          align="center"
        />
        <el-table-column
          prop="isBankSign"
          label="银行卡是否已签约"
          width="120"
          align="center"
        />
        <el-table-column prop="cz" label="操作" width="120" align="center" />
      </el-table>
      <!-- <div class="block">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[10, 20, 30, 40,50]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div> -->
    </div>
  </div>
</template>

<script>
import {
  queryInfoCMIS100001,
  queryInfo0CMIS100001,
  queryInfoCMIS100098,
} from "@/api/hubeixiaojin/queryInfo";
export default {
  name: "customerInfo",
  props: ["personalInfoData"],
  data() {
    return {
      customerName: "",
      idNo: "",
      sqbh: "",
      custInfo: [],
      total: 0,
      currentPage: 1,
    };
  },

  created() {
    // console.log('客户资料查询模块初始化：')
    var zjhm =
      sessionStorage.getItem("idNo") == ""
        ? this.idNo
        : sessionStorage.getItem("idNo"); //身份证号
    this.queryInfo(zjhm);
  },

  watch: {
    $route: function (to, from) {
      // console.log("监听【客户资料查询模块】route变化")
      this.$destroy();
    },
  },

  methods: {
    //客户资料查询
    queryInfo(str) {
      // console.log("123");
      let self = this;
      var objList = [];
      var applSeqList = []; //申请流水号列表
      var param = {
        idNo: typeof str === "string" ? str : this.idNo,
        applSeq: this.sqbh,
        customerName: this.customerName,
      };

      // //走申请流水查询逻辑：（单条）
      // if (this.sqbh.length > 0) {
      //   queryInfo0CMIS100001(this.sqbh).then((res) => {
      //     if (res.retCode === "200") {
      //       this.custInfo.push(res.data);
      //     } else {
      //       // console.log('单条申请流水查询失败2222')
      //       window.globalUiKit.notify("提示", "未查询到客户资料信息", "info");
      //     }
      //   });
      //   return;
      // }
      // //走身份证号查询逻辑：（多条）
      // // console.log('走身份证号多条数据查询逻辑')
      // if (this.idNo.length > 0) {
      //   // param = this.idNo;
      //   param = {
      //     idNo: this.idNo, //身份证号
      //   };
      // }

      // console.log("客户资料查询 参数："+param);
      if (param.idNo.length > 0) {
        queryInfoCMIS100098(param)
          .then((res) => {
            // console.log(res)
            if (res.retCode === "200") {
              // console.log('查询客户资料——调用CMIS100098接口成功')
              var applSeqList = res.data;
              //遍历列表，调用CMIS100001接口获取贷款信息
              if (applSeqList.length > 0) {
                queryInfoCMIS100001(applSeqList)
                  .then((res2) => {
                    // console.log(res2)
                    if (res2.retCode == "200") {
                      // console.log('查询成功,赋值custInfo')
                      self.custInfo = res2.data;

                      // var obj = {}
                      // var data = res2.data
                      //遍历循环拼参
                      // data.forEach((item) => {
                      //   console.log("item")
                      //   console.log(item)

                      //   var obj = {}
                      //   obj.applSeq = item.applSeq //申请编号
                      //   obj.custName = item.custName //客户名称
                      //   obj.idNo = item.idNo //身份证号
                      //   obj.loanTyp = item.loanTyp //业务品种（贷款品种）
                      //   obj.docChannel = item.docChannel //进件通路
                      //   obj.applyAmt = item.applyAmt //申请金额
                      //   obj.apprvAmt = item.apprvAmt //审批金额
                      //   //obj.sts_ = item.lcApptRelList[0].sts
                      //   console.log("obj")
                      //   console.log(obj)

                      //   self.custInfo.push(obj)

                      // })
                    } else {
                      // console.log('调用CMIS100001接口失败:')
                      window.globalUiKit.notify(
                        "提示",
                        "未查询到客户信息",
                        "info"
                      );
                    }
                  })
                  .catch((err) => {
                    window.globalUiKit.notify(
                      "提示",
                      "未查询到客户信息",
                      "error"
                    );
                    // console.log('调用CMIS100001接口异常:')
                    // console.log(err);
                  });
              } else {
                this.custInfo = [];
                window.globalUiKit.notify(
                  "提示",
                  "未查询到客户信息，请联系管理员",
                  "info"
                );
              }
            } else {
              // console.log(res.msg)
              window.globalUiKit.notify("提示", "未查询到客户资料信息", "info");
            }
          })
          .catch((err) => {
            // console.log("调用CMIS100098接口发生异常"+err);
          });
      } else {
        // console.log('客户资料查询 异常：无身份证号或申请编号')
        window.globalUiKit.notify("提示", "请输入身份证号或申请流水号", "info");
      }
    },

    //客户资料查询 重置
    restAll() {
      // console.log('重置【客户资料查询】页面数据')
      this.customerName = "";
      this.sqbh = "";
      this.idNo = "";
      this.custInfo = [];
    },

    //切换每页条数
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
    },
    //切换当前页
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
    },
  },
};
</script>

<style scoped></style>
